const { letDataToJsFile, getSlotHtmlStr, getPropsStr, getBtnsStr } = require("./_utils");

const defaultOptions = {
  description: "描述：暂无",
  withProps: true,
  operateBtns: ["edit", "delete"],
  idKey: "id",
  apiDel: "DeleteUserList",
  apiPath: "@/api-mock",
};
module.exports = {
  getTableStr(cols = [], rows = [], options) {
    const { description, withProps, operateBtns, idKey, apiDel, apiPath } = { ...defaultOptions, ...options };
    return `<!-- ${description} -->
<template>
  <BaseTable :cols="cols" :rows="rows" ${getBtnsStr(operateBtns, "operateBtns")}>
    ${getSlotHtmlStr(cols)}
  </BaseTable>
</template>
<script lang="ts" setup>
import { ref, reactive, watch, computed } from "vue";
import { ${apiDel} } from "${apiPath}";
import { handleBtnNext } from "@/utils";
${getPropsStr(withProps)}
const cols = ${letDataToJsFile(cols)};

const rows = ${letDataToJsFile(rows)};

function onOperateBtns(name: BtnName, row: CommonObj, next: FinallyNext) {
  const { ${idKey} } = row;
  handleBtnNext(
    {
      edit: () => handleEdit(row, next),
      delete: () => ${apiDel}({ ${idKey} }).then(() => next()),
    },
    name
  );
}
function handleEdit(row: CommonObj, next: FinallyNext) {
  // 处理编辑操作
}
</script>
<style lang="scss" scoped></style>`;
  },
};
